package utils;

import java.sql.*;

/**
 * 数据库帮助类
 * @author Administrator
 *
 */
public class DBUtils {
	/**
	 * 获得数据连接
	 * @return
	 */
	public static Connection getConn() {
		Connection conn = null;
		try {
			Class.forName("oracle.jdbc.OracleDriver");
			conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:ORCL","scott","tiger");
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		return conn;
	}
	
	/**
	 * 关闭数据连接
	 * @param conn
	 * @param pst
	 */
	public static void close(Connection conn ,Statement pst) {
		try {
			if ( pst != null ) pst.close();
			if ( conn != null ) conn.close();
		} catch ( SQLException e ) {
			e.printStackTrace();
		}
	}
}
